<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
>
<auth:data uri="/system/res/tree,/icon"/>
<head>
    <th:block th:include="common/head::noXadmin('添加资源')"/>
</head>
<body class="layui-layout layui-layout-admin">
<div class="layui-container">
    <form class="layui-form " th:action="@{/system/res/add}" method="post">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>基本信息</legend>
        </fieldset>
        <div class="layui-row layui-col-space30 " style="margin: 0px 30px 0px 30px ">
            <div class="layui-col-md12">
                <div class="layui-form-item">
                    <label class="layui-form-label is-required">上级资源</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="parentId" name="parentId" th:value="${res?.parentId}" readonly>
                        <input type="text" id="parentName" placeholder="上级资源" class="layui-input"
                               th:value="${parent?.resName}" lay-verify="required" readonly="readonly"
                               onclick="loadTree()">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label is-required">资源类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="resType" value="D" lay-filter="resType" title="目录"
                               th:checked="${res?.resType=='D'}">
                        <input type="radio" name="resType" value="M" lay-filter="resType" title="菜单"
                               th:checked="${res?.resType=='M'}">
                        <input type="radio" name="resType" value="B" lay-filter="resType" title="按钮"
                               th:checked="${res?.resType=='B'}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label is-required">资源名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="resName" autocomplete="off" placeholder="请输入角色名称" class="layui-input"
                               required lay-verify="required" th:value="${res?.resName}">
                    </div>
                </div>

                <div class="layui-form-item f_D">
                    <label class="layui-form-label">请求路径</label>
                    <div class="layui-input-block">
                        <input type="text" name="resPath" placeholder="请求路径"
                               autocomplete="off"
                               class="layui-input" th:value="${res?.resPath}">
                    </div>
                </div>
                <div class="layui-form-item f_D">
                    <label class="layui-form-label">资源标识</label>
                    <div class="layui-input-block">
                        <input type="text" name="resMark" placeholder="资源标识"
                               autocomplete="off"
                               class="layui-input" th:value="${res?.resMark}">
                    </div>
                </div>
                <div class="layui-form-item f_D f_B">
                    <label class="layui-form-label  ">打开方式</label>
                    <div class="layui-input-block">
                        <select name="target">
                            <option value="">打开方式</option>
                            <option value="TAB">页签</option>
                            <option value="ALERT">弹窗</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item is-required">
                    <label class="layui-form-label">显示排序</label>
                    <div class="layui-input-block">
                        <input type="number" name="order" value="0" placeholder="排序" autocomplete="off"
                               class="layui-input" lay-verify="required" th:value="${res?.order}">
                    </div>
                </div>
                <div class="layui-form-item f_B">
                    <label class="layui-form-label">图标</label>
                    <div class="layui-input-block">
                        <input type="text" id="icon" onclick="loadIcon()" name="icon" value="" placeholder="图标"
                               autocomplete="off"
                               class="layui-input" th:value="${res?.icon}">
                    </div>
                </div>
                <div class="layui-form-item " pane="">
                    <label class="layui-form-label">资源状态</label>
                    <div class="layui-input-block">

                        <input type="hidden" name="visible" id="visible" th:value="${res?.visible==null?1:res.visible}">
                        <input type="checkbox" lay-skin="switch" lay-filter="visible"
                               lay-text="显示|隐藏" value="0" th:checked="${res?.visible eq 0}">
                    </div>
                </div>

            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title">
            <legend>其他信息</legend>
        </fieldset>
        <div class="layui-row" style="margin: 0px 30px 0px 30px ">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" name="remark"
                              th:text="${res?.remark}"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="ok">保存</button>
                <button type="reset" class="layui-btn layui-btn-danger" lay-filter="close">重置</button>
            </div>
        </div>

    </form>

</div>
<script>
    function loadTree() {
        layui.use(['layer', 'jquery'], function () {
            var layer = layui.layer,
                $ = layui.jquery;
            layer.open({
                type: 2,
                width: 380,
                btn: ['确认', '取消'],
                content: "/system/res/tree?resId=0",
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    $("#parentId").val(body.find('#resId').val());
                    $("#parentName").val(body.find('#resName').val());
                    layer.close(index);
                }
            })
        })
    }

    function loadIcon() {
        layui.use(['layer', 'jquery'], function () {
            var layer = layui.layer,
                $ = layui.jquery;
            layer.open({
                type: 2,
                area: ['500px', '300px'],
                btn: ['确认', '取消'],
                content: "/icon",
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    $("#icon").val(body.find('#icon').val());
                    layer.close(index);
                }
            })
        })
    }

    layui.use(['form', 'layedit', 'laydate', 'jquery'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery
        ;
        var code = '[[${code}]]';
        var message = '[[${message}]]';
        if (code == 200) {
            layer.confirm(message, {
                icon: 1,
                title: '提示',
                btn: ["继续", "关闭"]
            }, function (index) {
                layer.close(index);
            }, function (index) {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });
        }
        form.on('switch(visible)', function (data) {
            if (data.elem.checked) {
                $("#visible").val(0);
            } else {
                $("#visible").val(1);
            }
        })
        form.on('radio(resType)', function (data) {
            $(".layui-form-item").show();
            $(".f_" + data.value).hide();
        });
    });
</script>

</body>

</html>
